﻿#!/usr/bin/python3
# coding=utf-8

"""
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

import menu
import random

def choose_one(foods, maxprice):
    minprice = min([ food[1] for food in foods]+[10000])
    if maxprice < minprice:
        return None;
    while True:
        s = random.choice(foods)
        if s[0] in menu.excluded_foods:
            continue
        if s[1] <= maxprice:
            return s
    

vegetable = [food for food in menu.foods if food[2] == menu.VEGETABLE]
meat = [food for food in menu.foods if food[2] == menu.MEAT]
soup = [food for food in menu.foods if food[2] == menu.SOUP]

#max_price = int(input("预算:"))
max_price = 1000
num_people = int(input("人数:"))
#order_soup = input("是否要汤？(y/n)")
order_soup = 'n'

order = []
total_price = 0

if order_soup.lower() == 'y':
    s = choose_one(soup, max_price-total_price)
    if s:
        total_price += s[1]
        order.append(s)

if num_people > len(meat) + len(vegetable) - len(menu.excluded_foods):
    num_people = len(meat) + len(vegetable) - len(menu.excluded_foods)
        
while len(order) < num_people:
    food = meat if len(order) % 2 == 1 else vegetable
    s = choose_one(food, max_price-total_price)
    if s:
        if s in order:
            continue
        total_price += s[1]
        order.append(s)
    else:
        break;
print("菜单如下:")
for food in order:
    print("{0} \t{1:5d}".format(food[0], food[1]))

print("总价\t\t{0:5d}".format(total_price))

    
